package com.syaccp.controller;


import com.github.pagehelper.PageInfo;
import com.syaccp.model.SysUser;
import com.syaccp.request.SysUserRequest;
import com.syaccp.service.UserService;
import com.syaccp.utils.Result;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author lixin
 * @since 2023-07-02
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;


    @GetMapping("/selectAll")
    public Result selectAll() throws SQLException {
        List<SysUser> users = userService.selectAll();

        return Result.success(users);
    }



    @GetMapping("/hello")
    public String hello(){
        return "aaa";
    }

    @PostMapping("/pageGetUser")
    @ResponseBody
    public Result pageGetUser(@RequestBody SysUserRequest sysUser){
        System.out.println(sysUser.getDeptId());
        PageInfo<SysUserRequest> pageInfo=userService.pageGetUser(sysUser.getIndex(),sysUser);
        System.out.println(pageInfo);
        for (SysUserRequest sysUserRequest : pageInfo.getList()) {
            System.out.println(sysUserRequest);
        }
        return Result.success(pageInfo);
    }

    @PostMapping("/addUser")
    @ResponseBody
    public Result addUser(@RequestBody SysUserRequest sysUser){
        int num=userService.addUser(sysUser);
        return Result.success(num);
    }

    @PutMapping("/updateUser")
    @ResponseBody
    public Result updateUser(@RequestBody SysUserRequest sysUser){

        int num=userService.updateUser(sysUser);
        return Result.success(num);
    }

}

